package member;

import member.Member;

import java.io.IOException;
import shared.PMF;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.jdo.PersistenceManager;

public class AddMemberServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static final String nextJSP = "/index_un.jsp"; // �U�@�ӭ���:getAvailableMember.jsp

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		
		request.setCharacterEncoding("BIG5");
		// String memberID = request.getParameter("MNO");
		String name_S = request.getParameter("name");
		String nickName_S = request.getParameter("nickName");
		
		
		
/*		String score_S = request.getParameter("score");
		String transTimes_S = request.getParameter("transTimes");
		String point_S = request.getParameter("point");
		String requirement_S = request.getParameter("requirement");*/
		String name = "";
		String nickName = "";
		int score = 0;
		int transTimes = 0;
		int point = 0;
		boolean requirement = false;
		try {
			name = name_S;
			nickName = nickName_S;
			/*
			score = Integer.parseInt(score_S);
			transTimes = Integer.parseInt(transTimes_S);
			point = Integer.parseInt(point_S);
			requirement = Boolean.parseBoolean(requirement_S);*/
		} catch (NumberFormatException e) {
			System.out.println("NAME沒有寫入");
		}
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			Member p = new Member(name, nickName, score, transTimes, point, requirement);
			pm.makePersistent(p);
		} finally {
			pm.close();
		}

		response.sendRedirect(nextJSP);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		doGet(request, response);
	}
}//AddMemberServlet
